package com.ctshk.rpc.order.scenic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.order.scenic.entity.ScenicOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 景点门票订单 Mapper 接口
 * </p>
 *
 * @author 张志朋
 * @since 2021-02-24
 */
public interface ScenicOrderMapper extends BaseMapper<ScenicOrder> {

    @Update("UPDATE t_scenic_order set scheduled_status = #{status}  where order_number = #{OrderNumber} ")
    Integer updateByOrderNumber(@Param("OrderNumber") String OrderNumber, @Param("status") Integer status);

    /**
     * 查询用户指定产品的票数
     * @param productId
     * @param userId
     * @return
     */
    @Select("SELECT sum(product_ticket_number) FROM `t_scenic_order` WHERE  product_id = #{productId}  \n" +
            "and is_agent =0 and salesman_id = #{userId} and scheduled_status not in (3)  ")
    Integer querySalaNumber(@Param("productId")Long productId,@Param("userId")Long userId);

    /**
     * 查询代理指定产品的票数
     * @param productId
     * @param id
     * @return
     */
    @Select("SELECT sum(product_ticket_number) FROM `t_scenic_order` WHERE  product_id = #{productId}  \n" +
            "and is_agent =1 and agency_id = #{id} and scheduled_status not in (3)  ")
    Integer querySalaNumberByAgent(@Param("productId")Long productId,@Param("id}")Long id);



}
